<%@page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<!-- public quote -->
<%@include file="/jsp/comm_css_include.jsp"%>
<!-- jqgrid-->
<link
	href="${basePath}/css/plugins/jqgriddemo/css/ui.jqgrid-bootstrap.min.css"
	rel="stylesheet" />
<link rel="stylesheet" type="text/css"
	href="${basePath}/css/zTreeStyle/zTreeStyle/zTreeStyle.css">
<!doctype html>
<html>
<head>
</head>
<body class="gray-bg">
	<div class="wrapper wrapper-content animated fadeInRight">
		<div class="iboxtitle">
			<span><i class="glyphicon glyphicon-map-marker"></i>&nbsp;预警配置</span>
			<a href="javascript:void(0)"></a>
		</div>
		<div class="ibox-content">
			<button type="button" class="btn dpbtn_green" onclick="add();">新增</button>
		</div>
		<div class="ibox-content">
			<div class="jqGrid_wrapper">
				<table id="table_list_1"></table>
				<div id="pager_list_1"></div>
			</div>
		</div>
	</div>
	<div class="contractDiv" id="contractDiv" style="display: none;">
		<form class="form-horizontal" id="commentForm">
			<div class="business-padding">
				<table cellpadding="0" cellspacing="0" border="0"
					bordercolor="#3B95C8" width="100%" class="buyinfor-table">
						<tr>
							<td width="25%" align="right"><label
								class="col-sm-3 control-label np">所在地区：</label></td>
							<td width="75%">
								<input type="hidden" id="orgId" name="orgId" /> <input
									type="hidden" id="orgCode" name="orgCode" /> <input
									id="orgName" name="orgName" readonly="readonly" type="text"
									class="form-control smalliconcur smallicon" required=""
									placeholder="机构名称(必填)" onclick="choseOrg();" />
							</td>
						</tr>
	
						<tr>
							<td width="25%" align="right"><label
								class="col-sm-3 control-label np">预警类型：</label></td>
							<td width="75%">
								<select class="select-control" id="warningType"
									name="warningType"></select>
							</td>
						</tr>
	
						<tr>
							<td width="25%" align="right"><label
								class="col-sm-3 control-label np">预警天数：</label></td>
							<td width="75%">
								<input id="warningDay" name="warningDay" type="number" min="0"
									class="form-control" required="" aria-required="true"
									placeholder="请输入预警天数(必填)">
							</td>
						</tr>
					</table>
				</div>
				<div class="padding-nono">
					<table cellpadding="0" cellspacing="0" border="0"
						bordercolor="#3B95C8" width="100%">
						<tr>
							<td width="100%" align="center">
								<div class="ibox-content">
									<button class="btn dpbtn_blue" type="button"
										onclick="dkszsave();">保存</button>
									<button class="btn dpbtn_red" type="button"
										onclick="dkszcancel();">取消</button>
								</div>
							</td>
						</tr>
					</table>
				</div>
			</form>
		</div>

		<div class="contractDiv" id="contractDivb" style="display: none;">
			<form class="form-horizontal" id="commentFormb">
				<div class="business-padding">
					<table cellpadding="0" cellspacing="0" border="0"
						bordercolor="#3B95C8" width="100%" class="buyinfor-table">
						<tr>
							<td width="25%" align="right"><label
								class="col-sm-3 control-label np">所在地区：</label></td>
							<td width="75%">
								<input type="hidden" id="id" /> <input id="orgNameb"
									name="orgName" readonly="readonly" type="text"
									class="form-control smalliconcur smallicon" required=""
									placeholder="机构名称(必填)" onclick="choseOrg();" />
							</td>
						</tr>

						<tr>
							<td width="25%" align="right"><label
								class="col-sm-3 control-label np">预警类型：</label></td>
							<td width="75%">
									<select class="select-control" id="warningTypeb"
										name="warningType"></select>
							</td>
						</tr>

						<tr>
							<td width="25%" align="right"><label
								class="col-sm-3 control-label np">预警天数：</label></td>
							<td width="75%">
								<input id="warningDayb" name="warningDay" type="number"
									min="0" class="form-control" required=""
									aria-required="true" placeholder="请输入预警天数(必填)">
							</td>
						</tr>
					</table>	
				</div>
				<div class="padding-nono">
					<table cellpadding="0" cellspacing="0" border="0"
						bordercolor="#3B95C8" width="100%">
						<tr>
							<td width="100%" align="center">
								<div class="ibox-content">
									<button class="btn dpbtn_blue" type="button"
										onclick="dkszupdate();">修改</button>
									<button class="btn dpbtn_red" type="button"
										onclick="dkszcancel();">取消</button>
								</div>
							</td>
						</tr>
					</table>
				</div>
			</form>
		</div>
		<!-- public quote -->
		<%@include file="/jsp/comm_js_include.jsp"%>
		<!-- custom js -->
		<%@include
			file="/js/common-dpqc/dpqc-validate/comm_validate_include.jsp"%>
		<!-- jqGrid -->
		<script type="text/javascript" charset="utf-8"
			src="${basePath}/js/plugins/jqgriddemo/js/jquery.jqGrid.min.js"></script>
		<script type="text/javascript" charset="utf-8"
			src="${basePath}/js/plugins/jqgriddemo/js/grid.locale-cn.min.js"></script>
		<script type="text/javascript"
			src="${basePath}/js/zTreeStyle/jquery.ztree.core.js"
			charset="utf-8"></script>
		<script type="text/javascript"
			src="${basePath}/js/zTreeStyle/jquery.ztree.excheck.js"
			charset="utf-8"></script>
		<!--
    	作者：zhangpp
    	时间：2017-04-06
    	描述：js
    -->
		<script type="text/javascript">
	    
	    var winWidth = $(window).width();
		var winHeight = $(window).height();
	    jQuery(function($) {  
	    	getData();
	    });
	    var getData = function()
	    {
	  var winWidth = $('div.ibox-content').width();
	        var winHeight = document.body.offsetHeight - 300;
	       var win = winWidth / 7 - 20;
  	 	   $.jgrid.defaults.styleUI = 'Bootstrap';
  	 	   
		  jQuery("#table_list_1").jqGrid
		  ({
			url:'${basePath}/OtherWarningConfigurationController/mulitList',
	        datatype : "json",
	        colNames : [ '主键', '所在地区','','预警类型','预警天数'],
	        colModel : [ 
	                     {name: 'replaceId', index: 'id', hidden:true},
	            		 {name: 'busiUnitCodeDisplay',index: 'busiUnitCode',width: win,align: "center"},
	            		 {name: 'warningType',index: 'warningType', hidden:true},
	            		 {name: 'warningTypeDisplay',index: 'warningType',width: win,align: "center"},
	            		 {name: 'warningDay',index: 'warningDay',width: win,align: "center"}
	                   ],
              mtype : "post",
              height: winHeight,
              width:winWidth,  
              autowidth: true,
              shrinkToFit: true,
              rowNum: 15,
              rowList: [15, 30, 45],
              viewrecords: true,
              pager: "#pager_list_1",
              sortorder : "desc",
              sortname : 'created',
              hidegrid: false,
              multiselect : false,
              altRows:true,
              altclass:'someClass',
              ondblClickRow:function(rowId,v,e)
              {	
            	  var rowData = $("#table_list_1").jqGrid("getRowData", rowId);
                  var id = rowData.replaceId;
                  $("#id").val(id);
                  $("#warningDayb").val(rowData.warningDay);
                  $("#warningTypeb").val(rowData.warningType);
                  $("#orgNameb").val(rowData.busiUnitCodeDisplay);
           		  updatelayer=layer.open({
         				  title:'修改',
         				  type: 1,
         				  area: ['400px', '400px'], //宽高
         				  content: $('#contractDivb')
         			});
              },
              jsonReader : {
            	  root:"result.rows",
            	  page: "result.page",
            	  total: "result.total",
            	  records: "result.records",
            	  repeatitems: false,
            	  id: "replaceId"
              },
              loadComplete:function(datas){
            	  if (datas.flag == "100100") {
                      layer.msg("查询成功!", {icon: 6, time: 1000});
                      return;
                  }
            	  if(datas.flag == '100802') {
    				  top.location.href = thisLoginUrl;
    				  return;
    			  }

            	  layer.msg(datas.message, {icon: 2});
              }
	      });
	    }
	    $(function(){
			$.dpAjax({
		    	url:'${basePath}/DataDictionaryController/getEnableList',
	 			data:{
	 				"parentValue":"MessageEventType",
	 				"addedValue1":"1"
	 			},
	 			success: function(datas){
	 				  if(datas.flag == "100100")
						  {
		 					  var result = datas.result.rows;
		 					  var programme_sel=[];
		 				      for(var i=0;i<result.length;i++){
		 				          var programme = result[i];
		 				          programme_sel.push('<option value="'+programme.value+'">'+programme.name+'</option>')
		 				      }
		 				     $("#warningType").html(programme_sel.join(' '));
		 				     $("#warningTypeb").html(programme_sel.join(' '));
							  return;
						  }
						  if(datas.flag == "100200")
		                  {
							  $.fn.showDatas({"datas":datas});
		                	  return;
		                  }
						  layer.msg(datas.message, {icon: 2});
	              }
		    	});
		 });
	    
		var dkszcancel = function(){
			layer.closeAll();
		}
	    
	    var choseOrg=function(){
	    	$.dpAjax({
	    		url:'${basePath}/BaseBusiUnitController/list',
    			success: function(datas){
	    			  if(datas.flag == "100100")
					  {
	    				  var content = '<div class="ibox-content" style="height: 480px;border: 1px solid #F5F5F6; overflow:auto;overflow-x: hidden;">'
	    						+ '	<div id="orgTree" class="ztree">&nbsp;</div>'
	    					+ '</div>'
	    					+ '<div class="ibox-content">'
	    					+ '	 <button class="btn dpbtn_green" type="button" onclick="confirmPower();">确定</button>'
	    					+ '	 <button class="btn dpbtn_red" type="button" onclick="cancelPower();">取消</button>'
	    					+ '</div>';

	    				index = layer.open({
	    					  title:'机构列表',
	    					  type: 1,
	    					  area: ['800px', '600px'], //宽高
	    					  content: content
	    				});
				    	var setting = {
			 					check: {
			 						enable: false
			 					},
			 					data: {
			 						simpleData: {
			 							enable: true
			 						}
			 					}
			 			 };			
    				  var zNodes = datas.result.rows;
    				  var list=[];
    				  for(var i=0;i<datas.result.rows.length;i++){
	    				  var obj=new Object();
    					  obj.id=datas.result.rows[i].replaceId;
    					  obj.name=datas.result.rows[i].orgName;
    					  obj.pId=datas.result.rows[i].parentId;
    					  obj.unitCode=datas.result.rows[i].orgCode;
    					  if(datas.result.rows[i].replaceId == 1){
    						  obj.open = true;
     					  } else {
     						 obj.open = false; 
     					  }
    					  list.push(obj);
    				  }
    				  $.fn.zTree.init($("#orgTree"), setting, list);
					  return;
					  }
					  if(datas.flag == "100200")
	                  {
						  $.fn.showDatas({"datas":datas});
	                	  return;
	                  }
                 }
	    	});
	    }
	    
	    var confirmPower = function()
	    {
	    	 var zTree = $.fn.zTree.getZTreeObj("orgTree"); 
	    	 var node=zTree.getSelectedNodes();
	    	 var treeNode = node[0];
	    	 var replaceId = treeNode.id;
	    	 if(replaceId == 1)
			  {
				  layer.msg('顶级节点无法选择！', {icon: 5});
				  return;
			  }
	    	 if(""!=node && node.length>0){
		    	 document.getElementById("orgName").value=node[0].name;
		    	 document.getElementById("orgId").value=node[0].id;
		    	 document.getElementById("orgCode").value=node[0].unitCode;
// 		    	 document.getElementById("orgNameb").value=node[0].name;
// 		    	 document.getElementById("orgIdb").value=node[0].id;
		    	 layer.close(index);
	    	 }
	    }
	    var updatelayer;
	    
	    
	    var addlayer;
	    var add=function(){
	    	addlayer=layer.open({
				  title:'新增',
				  type: 1,
				  area: ['400px', '400px'], //宽高
				  content: $('#contractDiv')
			});
	    }
	    var dkszsave=function(){
	    	var data={};
	    	data.warningType=$('#warningType option:selected').val();
	    	data.warningDay=$('#warningDay').val();
	    	data.busiUnitCode=$('#orgCode').val();
	    	var validstatus = $("#commentForm").valid();
	        if (validstatus) {
		    	$.dpAjax({
		    		url:'${basePath}/OtherWarningConfigurationController/save',
	    			data:data,
	    			success: function(datas){
	    			  if(datas.flag == "100100"){
	    			      $('#warningDay').val("");
	    			      $('#orgCode').val("");
	    			      $('#orgName').val("");
	    			      $("#orgNameb").val("");
						  layer.msg('执行成功！', {icon: 6});
						  layer.close(addlayer);
						  refresh();
						  return;
					  }
					  if(datas.flag == "100200")
	                  {
						  $.fn.showDatas({"datas":datas});
	                	  return;
	                  }
					  if(datas.flag=="101102"){
						  layer.msg('执行失败，预警类型在'+$('#orgName').val()+'已存在！', {icon: 5});
	                	  return;
					  }
	                }
		    	});
	        }	
	    }
	    var dkszupdate=function(){
	    	var data={};
	    	data.id=$("#id").val();
	    	data.warningType=$('#warningTypeb option:selected').val();
	    	data.warningDay=$('#warningDayb').val();
	    	data.busiUnitCode=$('#orgCode').val();
	    	var validstatus = $("#commentFormb").valid();
	        if (validstatus) {
		    	$.dpAjax({
		    		url:'${basePath}/OtherWarningConfigurationController/modify',
	    			data:data,
	    			success: function(datas){
	    			  if(datas.flag == "100100"){
	    				  $('#warningDayb').val("");
	    			      $('#orgCode').val("");
	    			      $('#orgNameb').val("");
							  layer.msg('执行成功！', {icon: 6});
							  layer.close(updatelayer);
							  refresh();
							  return;
						  }
						  if(datas.flag == "100200")
		                  {
							  $.fn.showDatas({"datas":datas});
		                	  return;
		                  }
						  if(datas.flag=="101102"){
							  layer.msg('执行失败，消息类型已存在！', {icon: 5});
		                	  return;
						  }
	                }
		    	});
	        }	
	    }
	    window.onresize = function()
	    {
	    	$("#table_list_1").setGridWidth($(window).width()-80);
	    }
	    
	    
	    var refresh = function()
	    {
	    	$("#table_list_1").jqGrid("setGridParam", { search: true }).trigger("reloadGrid", []);
	    }
	    
	    $(function(){	
	        $("#commentForm").validate({
	            rules: {
	            },
	            //重写showErrors
	            showErrors: function (errorMap, errorList) {
	                
	                $.each(errorList, function (i, v) {
	                    layer.tips(v.message, v.element, { time: 1500 });
	                    return false;
	                });  
	            },
	            /* 失去焦点时验证 */
	            onfocusout: false,
	            /*  键盘抬起不验证 */
	            onkeyup:false,
	        });
	    });  
	    
	    $(function(){	
	        $("#commentFormb").validate({
	            rules: {
	            },
	            //重写showErrors
	            showErrors: function (errorMap, errorList) {
	                
	                $.each(errorList, function (i, v) {
	                    layer.tips(v.message, v.element, { time: 1500 });
	                    return false;
	                });  
	            },
	            /* 失去焦点时验证 */
	            onfocusout: false,
	            /*  键盘抬起不验证 */
	            onkeyup:false,
	        });
	    });  
    </script>
</body>
</html>
